/**
 * 
 */
package org.x.starter4j.mina.http;

import java.io.IOException;

import org.x.starter4j.mina.http.server.HttpHandler;
import org.x.starter4j.mina.http.server.HttpRequestMessage;
import org.x.starter4j.mina.http.server.HttpResponseMessage;
import org.x.starter4j.mina.http.server.HttpServer;

/**
 * @author huangyang@p-an.com 2013年11月3日
 */
public class HttpServerDemo
{
	public static void main(final String[] args) throws IOException, InterruptedException
	{
		HttpServer server = new HttpServer();
		server.setEncoding("GB2312");
		server.setHttpHandler(new HttpHandler()
		{
			@Override
			public HttpResponseMessage handle(final HttpRequestMessage request)
			{
				String level = request.getParameter("level");
				System.out.println(request.getParameter("level"));
				System.out.println(request.getContext());
				HttpResponseMessage response = new HttpResponseMessage();
				response.setContentType("text/plain");
				response.setResponseCode(HttpResponseMessage.HTTP_STATUS_SUCCESS);
				response.appendBody("CONNECTED\n");
				response.appendBody(level);
				return response;
			}
		});
		server.run();

		// Thread.sleep(10000);
		// server.stop();
	}
}
